package org.lemon.transport.rule.engine.mqtt;

import io.netty.buffer.ByteBuf;
import io.netty.channel.EventLoopGroup;
import io.netty.handler.codec.mqtt.MqttQoS;
import io.netty.util.concurrent.Future;
import org.lemon.transport.rule.engine.mqtt.config.MqttClientConfig;
import org.lemon.transport.rule.engine.mqtt.handler.MqttClientCallback;
import org.lemon.transport.rule.engine.mqtt.handler.MqttHandler;
import org.lemon.transport.rule.engine.mqtt.model.MqttConnectResult;

public interface MqttClient {


    Future<MqttConnectResult> connect(String host);

    Future<MqttConnectResult> connect(String host, int port);

    Future<MqttConnectResult> connect(String host, int port, boolean reconnect);

    boolean isConnected();

    Future<MqttConnectResult> reconnect();

    EventLoopGroup getEventLoop();

    void setEventLoop(EventLoopGroup eventLoop);

    Future<Void> on(String topic, MqttHandler handler);

    Future<Void> on(String topic, MqttHandler handler, MqttQoS qos);

    Future<Void> once(String topic, MqttHandler handler);

    Future<Void> once(String topic, MqttHandler handler, MqttQoS qos);

    Future<Void> off(String topic, MqttHandler handler);

    Future<Void> off(String topic);

    Future<Void> publish(String topic, ByteBuf payload);

    Future<Void> publish(String topic, ByteBuf payload, MqttQoS qos);

    Future<Void> publish(String topic, ByteBuf payload, boolean retain);

    Future<Void> publish(String topic, ByteBuf payload, MqttQoS qos, boolean retain);

    MqttClientConfig getClientConfig();

    static MqttClient create(MqttClientConfig config, MqttHandler defaultHandler) {
        return new MqttClientImpl(config, defaultHandler);
    }

    void disconnect();

    void setCallback(MqttClientCallback callback);
}
